<%-- 
    Document   : getStop
    Created on : Jul 28, 2009, 11:25:26 AM
    Author     : david
--%>
<%@page contentType="text/html" pageEncoding="UTF-8" import="com.appspot.nnaplanner.DAL.*"%>
<%
            if (request.getQueryString() == null) {
                out.print("{\"success\": \"false\", \"msg\":\"No id provided\"}");
            } else {
                if (request.getQueryString().isEmpty()) {
                    out.print("{\"success\": \"false\", \"msg\":\"No id provided\"}");
                } else {
                    String id = request.getParameter("id").trim();
                    try {
                        DALStop ds = new DALStop();
                        ds = DAL.getByID(ds, id);
                        if (request.getParameter("xml") != null) {
                            response.setContentType("text/xml");
                            out.clear();
                            out.print("<?xml version=\"1.0\"?>\n");;
                            out.print("<stop id=\"" + ds.getID() + "\">");
                            out.print("<name>");
                            out.print(ds.getName());
                            out.print("</name>");
                            out.print("<description>");
                            out.print(ds.getDescription());
                            out.print("</description>");
                            out.print("<connections>");
                            out.print(ds.getConnectionCount());
                            out.print("</connections>");
                            out.print("<keywords>");
                            for (String word : ds.getKeywords() ) {
                                out.print("<word>");
                                out.print(word);
                                out.print("</word>");
                            }
                            out.print("</keywords>");
                            out.print("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:geo=\"http://www.w3.org/2003/01/geo/wgs84_pos#\">");
                            out.print("<geo:Point>");
                            out.print("<geo:lat>");
                            out.print(ds.getLatitude());
                            out.print("</geo:lat>");
                            out.print("<geo:long>");
                            out.print(ds.getLongitude());
                            out.print("</geo:long>");
                            out.print("</geo:Point>");
                            out.print("</rdf:RDF>");
                            out.print("</stop>");
                        } else if (request.getParameter("csv") != null) {
                            response.setContentType("text/csv");
                            out.clear();
                            out.print(ds.getID());
                            out.print(",");
                            out.print(ds.getName());
                            out.print(",");
                            out.print(ds.getDescription());
                            out.print(",");
                            out.print(ds.getLatitude());
                            out.print(",");
                            out.print(ds.getLongitude());
                            out.print(",");
                            out.print(ds.getConnectionCount());
                            out.print(",");
                            out.print(ds.isConnected());                       
                         } else {
                            out.print("{\"success\": \"true\", \"data\":{\"id\":\"");
                            out.print(ds.getID());
                            out.print("\", \"name\": \"");
                            out.print(ds.getName());
                            out.print("\", \"description\":\"");
                            out.print(ds.getDescription());
                            out.print("\", \"latitude\":\"");
                            out.print(ds.getLatitude());
                            out.print("\", \"longitude\":\"");
                            out.print(ds.getLongitude());
                            out.print("\", \"keywords\":\"");
                            out.print(ds.getKeywords());
                            out.print("\", \"connections\":\"");
                            out.print(ds.getConnectionCount());
                            out.print("\", \"connected\": \"");
                            out.print(ds.isConnected());
                            out.print("\"} }");
                        }
                    } catch (Exception ex) {
                        out.print("{\"success\": \"false\" }");
                    }
                }
            }
%>